#include <opencv2/core/hal/interface.h>
#include <iostream>
#include <opencv2/core/matx.hpp>
#include <opencv2/core/types.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include "example.h"
#include<stdio.h>
#include<vector>

int main()
{
    cv::Mat image = cv::imread("/home/qb/qb_2021111239/qb_2021111239/week03/work2/picture/dog.jpg");
    cv::Mat gray;
    //访问以下坐标点的像素值
    cv::Point2i point1(90, 25);
    cv::Point2i point2(152, 96);
    cv::Point2i point3(561, 36);
    cv::Point2i point4(326, 514);
    cv::Point2i point5(422, 46);
    
    FILE *fp=fopen("../output.txt","w");
    if(fp==NULL){
        printf("file open error!\n");
        return -1;
    }

    cv::Point2i point[5]={point1,point2,point3,point4,point5};
    for (int i=0;i<5;i++){
        int line,col;
        line=point[i].y;
        col=point[i].x;
        cv::Vec3b arr=image.at<cv::Vec3b>(line,col);
        fprintf(fp,"行：%d 列：%d  BGR:%u,%u,%u\n",line,col,arr[0],arr[1],arr[2]);
    }
    
    
    cv::cvtColor(image,gray,cv::COLOR_BGR2GRAY);
    for (int i=0;i<5;i++){
        int line,col;
        line=point[i].y;
        col=point[i].x;

        fprintf(fp,"行：%d 列：%d  GRAY:%d\n",line,col,static_cast<int>(gray.at<uchar>(line,col)));
    }
    fclose(fp);

    cv::namedWindow("演示输出图像", cv::WINDOW_NORMAL);
    cv::imshow("演示输出图像", image);
    //如果不加waitkey,显示窗口一闪而过就结束了
    cv::waitKey(0);
    return 0;
}
